package com.server.llh.llhserverwork.activity.food;

import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TextView;

import com.family.llh.lelaohuitoastview.dialog.toast.T;
import com.google.gson.Gson;
import com.lelaohui.net.listener.NetDataListener;
import com.lelaohui.net.netmanager.INetRequestManager;
import com.lelaohui.net.netmanager.NetRequestManager;
import com.lelaohui.net.request.LRequest;
import com.lelaohui.net.utils.UrlsTools;

import com.llh.llhsuppliers.R;
import com.server.llh.llhserverwork.activity.base.LlhBaseNFCActivity;
import com.server.llh.llhserverwork.activity.my.LlhAddAddressActivity;
import com.server.llh.llhserverwork.adapter.AccountAdapter;
import com.server.llh.llhserverwork.adapter.LlhAddressItemAdapter;

import com.server.llh.llhserverwork.adapter.ShopFoodOrderInfo;
import com.server.llh.llhserverwork.adapter.base.ListViewDataAdapter;
import com.server.llh.llhserverwork.bean.Account;
import com.server.llh.llhserverwork.bean.AccountConstant;
import com.server.llh.llhserverwork.bean.AddressManagerBean;
import com.server.llh.llhserverwork.bean.Constants;
import com.server.llh.llhserverwork.bean.FoodOrderInfoListBean;

import com.server.llh.llhserverwork.bean.FoodPayBean;
import com.server.llh.llhserverwork.bean.MyAddress;
import com.server.llh.llhserverwork.bean.PayList;
import com.server.llh.llhserverwork.bean.ProductBean;
import com.server.llh.llhserverwork.bean.UserDataInfoBean;
import com.server.llh.llhserverwork.port.ClearViewDataInterface;
import com.server.llh.llhserverwork.receiver.GetCardBroadCast;
import com.server.llh.llhserverwork.utils.Constant;
import com.server.llh.llhserverwork.utils.ServerPort;
import com.server.llh.llhserverwork.utils.SharedPreferenceUtil;
import com.server.llh.llhserverwork.utils.ToastTool;
import com.server.llh.llhserverwork.view.AddListView;
import com.server.llh.llhserverwork.view.AlertDialog;
import com.server.llh.llhserverwork.view.CheckableLinearLayout;
import com.server.llh.llhserverwork.view.HorizontalListView;


import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by ZTF on 2017-06-13.
 * 餐饮下单提交页面
 */

public class SubFoodOrderInfoActivity extends LlhBaseNFCActivity {
    private static final String TAG = "SubFoodOrder";
    @BindView(R.id.left_btn)
    ImageButton leftBtn;
    @BindView(R.id.titlebar_text)
    TextView titlebarText;
    @BindView(R.id.right_btn)
    Button rightBtn;
    @BindView(R.id.my_user_name)
    TextView myUserName;
    @BindView(R.id.user_old_man_sp)
    TextView userOldManSp;
    @BindView(R.id.view_line)
    LinearLayout viewLine;
    @BindView(R.id.addAddress)
    LinearLayout addAddress1;
    @BindView(R.id.add_address)
    LinearLayout addAddress;
    @BindView(R.id.addressTxt)
    TextView addressTxt;
    @BindView(R.id.userNameTxt)
    TextView userNameTxt;
    @BindView(R.id.userPhoneTxt)
    TextView userPhoneTxt;
    @BindView(R.id.image_break)
    ImageView imageBreak;
    @BindView(R.id.address_content)
    RelativeLayout addressContent;
    @BindView(R.id.show_address_all)
    CheckableLinearLayout showAddressAll;
    @BindView(R.id.address)
    LinearLayout address;
    @BindView(R.id.address_lv)
    AddListView addressLv;
    @BindView(R.id.layout_show)
    ImageView layoutShow;
    @BindView(R.id.view_pay)
    RelativeLayout viewPay;
    @BindView(R.id.radio0)
    ImageView radio0;
    @BindView(R.id.relative1)
    RelativeLayout relative1;
    @BindView(R.id.radio1)
    ImageView radio1;
    @BindView(R.id.relative2)
    RelativeLayout relative2;
    @BindView(R.id.LinearLayout1)
    LinearLayout LinearLayout1;

    @BindView(R.id.order_content)
    LinearLayout orderContent;
    @BindView(R.id.sv_order_content)
    ScrollView svOrderContent;
    @BindView(R.id.text_money)
    TextView textMoney;
    @BindView(R.id.text_money_count)
    TextView textMoneyCount;
    @BindView(R.id.btn_commint)
    Button btnCommint;
    @BindView(R.id.show_address)
    RelativeLayout showAddress;

    public static FoodOrderInfoListBean foodOrderInfoListBean = null;
    @BindView(R.id.food_time)
    TextView foodTime;
    @BindView(R.id.show_num)
    TextView show_num;
    @BindView(R.id.horizon_listview)
    HorizontalListView horizonListview;
    public static List<ProductBean> product = null;
    String mUserId, mOrgId, mUserName1, mUserId1, mUserName, morgId, mToken, mOrgType, isScope, mealTime;
    View view;
    @BindView(R.id.money_name)
    TextView moneyName;
    @BindView(R.id.yunfei_name)
    TextView yunfeiName;
    @BindView(R.id.money_num)
    TextView moneyNum;
    @BindView(R.id.yunfei_num)
    TextView yunfeiNum;
    @BindView(R.id.zhifu_Style)
    TextView zhifuStyle;
    @BindView(R.id.zhifu_card)
    TextView zhifuCard;
    @BindView(R.id.pay_sp)
    Spinner paySp;

    private TextView add_Address;
    private List<MyAddress> objects = new ArrayList<MyAddress>();
    LlhAddressItemAdapter llhAddressItemAdapter = null;
    int yunfei = 0;
    double totalMoney, mBanlance;
    List<FoodOrderInfoListBean.DataBean> dataBeanLists = null;
    GetCardBroadCast getCardBroadCast = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

        IntentFilter filter = new IntentFilter();
        filter.addAction(Constant.READ_CARDACTION);
        getCardBroadCast = new GetCardBroadCast();
        getCardBroadCast.setmHandler(handler);
        getLbm().registerReceiver(getCardBroadCast, filter);
        titlebarText.setText("提交订单");
        if (getIntent() != null) {
            isScope = getIntent().getStringExtra("isScope");
            mealTime = getIntent().getStringExtra("mealTime");
            if ("0".equals(isScope)) {
                foodTime.setText("今日" + getMealTime(mealTime));
            } else if ("1".equals(isScope)) {
                foodTime.setText("明日" + getMealTime(mealTime));
            } else {
                foodTime.setText("后日" + getMealTime(mealTime));
            }
        }
        addressLv.setVisibility(View.GONE);

        mOrgType = SharedPreferenceUtil.getUserInfo(Constants.UserInfo.ORG_TYPE, getApplicationContext());
        mUserName = SharedPreferenceUtil.getUserInfo(Constants.UserInfo.USER_NAMW, getApplicationContext());
        mUserId1 = SharedPreferenceUtil.getUserInfo(Constants.UserInfo.USER_ID, getApplicationContext());
        morgId = SharedPreferenceUtil.getUserInfo(Constants.UserInfo.ORG_ID, getApplicationContext());
        mToken = SharedPreferenceUtil.getUserInfo(Constants.UserInfo.TOKEN_STR, getApplicationContext());

        foodOrderInfoListBean = LlhFoodInfoActivity.foodOrderInfoListBean;
        if (foodOrderInfoListBean != null) {
            totalMoney = foodOrderInfoListBean.getData().get(0).getAllPrice();
            dataBeanLists = foodOrderInfoListBean.getData();
            textMoneyCount.setText("¥" + totalMoney + "元");
            for (int i = 0; i < foodOrderInfoListBean.getData().size(); i++) {
                for (int j = 0; j < foodOrderInfoListBean.getData().get(i).getProductList().size(); j++) {
                    for (int f = 0; f < foodOrderInfoListBean.getData().get(j).getProductList().size(); f++) {
                        yunfei = foodOrderInfoListBean.getData().get(j).getProductList().get(f).getSupplierDistr();
                        product = foodOrderInfoListBean.getData().get(j).getProductList().get(f).getSupplierProduct();
                    }
                }
            }
            moneyNum.setText("¥" + (totalMoney - yunfei) + "元");
            yunfeiNum.setText("¥" + yunfei + "元");
            if (product != null && product.size() > 0) {
                ListViewDataAdapter<ProductBean> adapter = new ListViewDataAdapter<ProductBean>(null);
                adapter.update(product);
                adapter.setViewHolderClass(null, ShopFoodOrderInfo.class, this);
                horizonListview.setAdapter(adapter);
                show_num.setText("共" + product.size() + "件");
                show_num.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getApplicationContext(), FoodOrderInfoActivity.class);
                        startActivity(intent);
                    }
                });
            }
        }
        view = LayoutInflater.from(SubFoodOrderInfoActivity.this).inflate(R.layout.llh_buttom_view, null);
        add_Address = (TextView) view.findViewById(R.id.add_address2);
        addressLv.addFooterView(view);
        paySp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                payTypeInt = accountList.get(position).getAcctype();
                idlong = accountList.get(position).getAccid();
                orgIds = accountList.get(position).getOrgId();
                mBanlance = accountList.get(position).getBalance();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

        addAddress1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (userDataInfoBean == null && "".equals(userDataInfoBean.getData().getUserId())) {
                    T.showAnimToast(getApplicationContext(), "请刷卡获取用户信息!");
                    return;
                }
                if (addAddress1 != null && addAddress1.getVisibility() == View.VISIBLE) {
                    try{
                        if (userDataInfoBean != null &&! "".equals(userDataInfoBean.getData().getUserId())) {
                            Intent intent = new Intent(getApplicationContext(), LlhAddAddressActivity.class);
                            intent.putExtra("intentType", "1");
                            intent.putExtra("code", "0");
                            intent.putExtra("userId", mUserId);
                            startActivity(intent);
                            return;
                        }else{
                            T.showAnimToast(getApplicationContext(), "请刷卡获取用户信息!");
                        }
                    }catch (Exception E){
                        T.showAnimToast(getApplicationContext(), "请刷卡获取用户信息!");
                    }

                }
            }
        });
    }

    private void setAddressData(List<AddressManagerBean.DataBean> dataBeanList) {
        objects = new ArrayList<MyAddress>();
        for (int i = 0; i < dataBeanList.size(); i++) {
            MyAddress myAddress = new MyAddress();
            if (dataBeanList.get(i).getAddressType() == 1) {
                myAddress.setUserName(dataBeanList.get(i).getContactName());
                myAddress.setAddressPhone(dataBeanList.get(i).getContactPhone());
                myAddress.setAddress(dataBeanList.get(i).getAddressDetail());
                myAddress.setAddressId(dataBeanList.get(i).getAddressId() + "");
                myAddress.setAddressType(dataBeanList.get(i).getAddressType() + "");
                myAddress.setAddressAll(dataBeanList.get(i).getAddressAll());
            } else if (dataBeanList.get(i).getAddressType() == 4) {
                myAddress.setUserName("餐厅");
                myAddress.setAddressType(dataBeanList.get(i).getAddressType() + "");
                myAddress.setAddress(dataBeanList.get(i).getAddressDetail());
                myAddress.setAddressAll(dataBeanList.get(i).getAddressAll());
            } else {
                myAddress.setUserName("小餐桌地址");
                myAddress.setAddressType(dataBeanList.get(i).getAddressType() + "");
                myAddress.setAddress(dataBeanList.get(i).getAddressDetail());
                myAddress.setAddressAll(dataBeanList.get(i).getAddressAll());
            }
            objects.add(myAddress);
        }
        if (llhAddressItemAdapter == null) {
            llhAddressItemAdapter = new LlhAddressItemAdapter(getApplicationContext(), objects);
            addressLv.setAdapter(llhAddressItemAdapter);
            addressLv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    addressLv.setSelected(true);
                    addressLv.setSelection(0);
                    addressLv.setItemChecked(0, true);
                    addressLv.performItemClick(addressLv.getChildAt(0), 0, 0);
                    addressLv.setVisibility(View.GONE);
                }
            }, 500);
        } else {
            llhAddressItemAdapter.setObjects(objects);
            llhAddressItemAdapter.notifyDataSetChanged();
        }
        addressLv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (ListView.CHOICE_MODE_SINGLE == addressLv.getChoiceMode()) {
                    setShowAddress(position);
                    setShowAddress();
                }
            }
        });
        add_Address.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try{
                    if (userDataInfoBean != null &&! "".equals(userDataInfoBean.getData().getUserId())) {
                        Intent intent = new Intent(getApplicationContext(), LlhAddAddressActivity.class);
                        intent.putExtra("intentType", "1");
                        intent.putExtra("code", "0");
                        intent.putExtra("userId", mUserId);
                        startActivity(intent);
                        return;
                    }else{
                        T.showAnimToast(getApplicationContext(), "请刷卡获取用户信息!");
                    }
                }catch (Exception E){

                }


            }
        });
    }


    String cardId;
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == -1000) {
                cardId = String.valueOf(msg.obj);
                Log.d(TAG, "cardId==" + cardId);
                getUserInfo(String.valueOf(cardId));
            }
        }
    };


    AddressManagerBean addressManagerBean = null;

    //获取所有地址
    public void getAllAddress(String userId, String orgId) {
        LRequest lRequest = new LRequest();
        lRequest.addParam("token", mToken);
        lRequest.addParam("userId", userId);
        lRequest.addParam("orgId", orgId);
        lRequest.setUri(ServerPort.GET_ALL_ADDRESS_DATA);
        lRequest.setUriType("");
        lRequest.setIp(UrlsTools.REQ_URL);
        lRequest.setType(String.class);
        requestData(lRequest, new NetDataListener<String>() {
            @Override
            public void onError(Throwable t) {
                T.showAnimErrorToast(getApplicationContext(), "获取失败！");
            }

            @Override
            public void onNext(String responseBean, String code) {
                if (responseBean != null && Constants.RESPON_SUCC_CODE.equals(code)) {
                    dataBeanList.clear();
                    addressManagerBean = new Gson().fromJson(responseBean.toString(), AddressManagerBean.class);
                    dataBeanList = addressManagerBean.getData();
                    if (dataBeanList != null && dataBeanList.size() > 0) {
                        addAddress.setVisibility(View.GONE);
                        address.setVisibility(View.VISIBLE);
                        AddressManagerBean.DataBean dataBean = new AddressManagerBean.DataBean();
                        dataBean.setAddressAll("餐厅");
                        dataBean.setAddressId(0);
                        dataBean.setAddressType(4);
                        dataBeanList.add(dataBean);
                        setAddressData(dataBeanList);
                        for (int i = 0; i < dataBeanList.size(); i++) {
                            if ("1".equals(dataBeanList.get(i).getAddressDefault())) {
                                setShowAddress(i);
                                return;
                            } else {
                                setShowAddress(0);
                            }
                        }
                    } else {
                        addAddress.setVisibility(View.VISIBLE);
                        address.setVisibility(View.GONE);
                    }
                } else {
                    addAddress.setVisibility(View.VISIBLE);
                    address.setVisibility(View.GONE);
                    T.showAnimToast(getApplicationContext(), "暂时没有获取地址信息！");
                }
            }
        });
    }

    //提交订单接口
    public void uploadDataInfo(String oldManId, String userId, String
            address, String mealTime, String isDistr, String isScope,
                               String totalMoney, String phone,
                               String orderPersonName, String orderData, String payLists) {
        try {
            LRequest lRequest = new LRequest();
            lRequest.addParam("oldManId", oldManId);
            lRequest.addParam("address", address);
            lRequest.addParam("isDistr", isDistr);
            lRequest.addParam("totalMoney", totalMoney);
            lRequest.addParam("phone", phone);
            Log.d(TAG, "oldManId==" + oldManId + "address==" + address + "isDistr==" + isDistr + "totalMoney==" + totalMoney + "phone==" + phone);
            lRequest.addParam("orderPersonName", orderPersonName);
            lRequest.addParam("orderData", orderData);
//          lRequest.addParam("orderData", URLEncoder.encode(orderData, "UTF-8"));
            lRequest.addParam("userId", oldManId);
            lRequest.addParam("mealTime", mealTime);
            lRequest.addParam("isScope", isScope);
            lRequest.addParam("token", mToken);
            Log.d(TAG, "orderPersonName==" + orderPersonName + "orderData==" + orderData + "userId==" + userId + "mealTime==" + mealTime + "isScope==" + isScope);
            if ("".equals(payLists)) {
                lRequest.addParam("payType", 5);
            } else {
                Log.d(TAG, "payLists==" + payLists.toString());
                lRequest.addParam("payList", payLists);
//                lRequest.addParam("payList", URLEncoder.encode(payLists, "utf-8"));
            }
            lRequest.addParam("channel", 1);
            lRequest.setUri(ServerPort.CREATE_ORDER_LIST);
            lRequest.setUriType(UrlsTools.FOOD_INFO);
            lRequest.setType(String.class);
            requestData(lRequest, new NetDataListener<String>() {
                @Override
                public void onError(Throwable t) {
                    T.showAnimErrorToast(getApplicationContext(), "请求超时！");
                }

                @Override
                public void onNext(String responseBean, String code) {
                    if (responseBean != null && Constants.RESPON_SUCC_CODE.equals(code)) {
                        foodPayBean = new Gson().fromJson(responseBean, FoodPayBean.class);
                        if (foodPayBean != null) {
                            String payList = new Gson().toJson(foodPayBean.getData().getPayList());
                            double totalFee = foodPayBean.getData().getTotalFee();
                            String orderid = foodPayBean.getData().getOrderid();
                            payByCard(mUserId, orderid, payList, totalFee);
                        }
                        Log.d(TAG, "responseBean==" + responseBean);
                    } else {
                        T.showAnimToast(getApplicationContext(), "提交订单失败！");
                    }
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    FoodPayBean foodPayBean;
    private int payTypeInt;

    @OnClick({R.id.left_btn, R.id.image_break, R.id.relative1, R.id.relative2, R.id.btn_commint})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.left_btn:
                onBackPressed();
                break;
            case R.id.btn_commint:
                Log.d(TAG, "addressType==" + addressType);
                if ("4".equals(addressType)) {
                    addressStr = addressTxt.getText().toString();
                    isDistr = "0";
                } else {
                    isDistr = "1";
                    addressStr = addressTxt.getText().toString();
                    addressName = userNameTxt.getText().toString();
                    addressPhone = userPhoneTxt.getText().toString();
                }
                String data = new Gson().toJson(dataBeanLists);
                Log.d(TAG, "data==" + data);
                if (payTypeInt == 5) {
                    uploadDataInfo(mUserId, mUserId1, addressStr, mealTime, isDistr, isScope, String.valueOf(totalMoney), addressPhone, mUserName, data, "");
                    return;
                } else {
                    if (userDataInfoBean == null || mUserId == null || "".equals(mUserId)) {
                        T.showAnimToast(getApplicationContext(), "用户信息不能为空，请刷卡！");
                        return;
                    } else if (totalMoney > mBanlance) {
                        T.showAnimToast(getApplicationContext(), "账户余额足，请切换其他账户或充值！");
                        return;
                    } else {
                        PayList payList = payListDate(idlong, payTypeInt, totalMoney, orgIds);
                        String payLists = new Gson().toJson(payList);
                        Log.d(TAG, "payLists===" + payLists + "orgIds==" + orgIds);
                        uploadDataInfo(mUserId, mUserId1, addressStr, mealTime, isDistr, isScope, String.valueOf(totalMoney), addressPhone, mUserName1, data, payLists);
                    }
                }
                break;
            case R.id.image_break:
                setShowAddress();
                break;
        }
    }


    private void setShowAddress() {
        if (objects != null && addressLv.getVisibility() == View.GONE) {
            imageBreak.setVisibility(View.VISIBLE);
            addressLv.setVisibility(View.VISIBLE);
        } else if (addressLv.getVisibility() == View.VISIBLE) {
            addressLv.setVisibility(View.GONE);
        }
    }

    /**
     * 设置显示地址信息
     *
     * @param i
     */
    private String addressId, idlong, orgIds, addressStr, isDistr, addressName, addressPhone, addressAll, addressType;
    List<AddressManagerBean.DataBean> dataBeanList = new ArrayList<AddressManagerBean.DataBean>();

    private void setShowAddress(int i) {
        if (dataBeanList != null && dataBeanList.size() > 0) {
            addressId = dataBeanList.get(i).getAddressId() + "";
            if (dataBeanList.get(i).getContactName() != null) {
                addressName = dataBeanList.get(i).getContactName();
                userNameTxt.setText("" + addressName);
            } else {
                userNameTxt.setText("");
            }
            if (dataBeanList.get(i).getContactPhone() != null) {
                addressPhone = dataBeanList.get(i).getContactPhone();
                userPhoneTxt.setText("" + addressPhone);
            } else {
                userPhoneTxt.setText("");
            }
            if (dataBeanList.get(i).getAddressDetail() != null) {
                addressAll = dataBeanList.get(i).getAddressAll();
                addressTxt.setText(addressAll);
            } else {
                addressTxt.setText("小餐桌地址");
            }
            addressType = dataBeanList.get(i).getAddressType() + "";
            if ("4".equals(addressType)) {
                addressTxt.setText("餐厅");
            }
        }
    }

    public String getMealTime(String mealTime) {
        if ("1".equals(mealTime)) {
            mealTime = "早餐";
        } else if ("2".equals(mealTime)) {
            mealTime = "午餐";
        } else if ("3".equals(mealTime)) {
            mealTime = "晚餐";
        }
        return mealTime;
    }

    /**
     * 支付方式
     *
     * @param getAcctype
     * @return
     */
    public PayList payListDate(String id, int getAcctype, double balanceD, String orgIds) {
        PayList payList = new PayList();
        if (getAcctype == 1) {
            payList.add(id, AccountConstant.PayType.CASH_ACCOUNT, balanceD, orgIds);
        } else if (getAcctype == 7 || getAcctype == 6) {
            payList.add(id, AccountConstant.PayType.ACTIVE_CARD, balanceD, orgIds);
        }
        payList.setOrderid("");
        payList.setConsumeType(AccountConstant.ConsumeType.CONSUME_CATERING);
        return payList;
    }

    Account account = null;
    AccountAdapter accountAdapter = null;
    List<Account.DataBean> accountList = new ArrayList<Account.DataBean>();

    public void accoutByRelated(String userId) {
        LRequest lRequest = new LRequest();
        lRequest.addParam("token", mToken);
        lRequest.addParam("userId", userId);
        lRequest.addParam("accTypes", "1,6,7,10");
        lRequest.setUri(ServerPort.ACC_BY_RELATED);
        lRequest.setUriType(UrlsTools.ACCOUNT_INFO);
        lRequest.setIp(UrlsTools.REQ_URL);
        lRequest.setType(String.class);
        requestData(lRequest, new NetDataListener<String>() {
            @Override
            public void onError(Throwable t) {
                T.showAnimErrorToast(getApplicationContext(), "请求超时！");
            }

            @Override
            public void onNext(String responseBean, String code) {
                if (responseBean != null) {
                    Log.d(TAG, "responseBean222==" + responseBean);
                    account = new Gson().fromJson(responseBean, Account.class);
                    if (account != null) {
                        if (account.getData() != null && account.getData().size() > 0) {
                            accountList = account.getData();
//                            dataBean = new Account.DataBean();
//                            dataBean.setAccid("5");
//                            dataBean.setAcctype(5);
//                            dataBean.setCardName("支付宝");
//                            accountList.add(dataBean);
                            accountAdapter = new AccountAdapter(getApplicationContext(), accountList);
                            paySp.setAdapter(accountAdapter);
                        }
                    }
                }
            }
        });
    }

    UserDataInfoBean userDataInfoBean = null;

    public void getUserInfo(String icNumber) {
        LRequest lRequest = new LRequest();
        lRequest.addParam("token", mToken);
        lRequest.addParam("icNumber", icNumber);
        lRequest.setUri(ServerPort.GET_CARD_INFO);
        lRequest.setUriType("");
        lRequest.setIp(UrlsTools.REQ_URL);
        lRequest.setType(String.class);
        requestData(lRequest, new NetDataListener<String>() {
            @Override
            public void onError(Throwable t) {
                T.showAnimErrorToast(getApplicationContext(), "请求超时！");
            }

            @Override
            public void onNext(String responseBean, String code) {
                if (responseBean != null && "0".equals(code)) {
                    userDataInfoBean = new Gson().fromJson(responseBean, UserDataInfoBean.class);
                    userOldManSp.setText(userDataInfoBean.getData().getUserName());
                    myUserName.setText("请选择");
                    mOrgId = userDataInfoBean.getData().getUserOrgId();
                    mUserId = userDataInfoBean.getData().getUserId();
                    if (userDataInfoBean.getData().getUserNickName() != null) {
                        mUserName1 = userDataInfoBean.getData().getUserName() + "(" + userDataInfoBean.getData().getUserNickName() + ")";
                    } else {
                        mUserName1 = userDataInfoBean.getData().getUserName();
                    }
                    accoutByRelated(userDataInfoBean.getData().getUserId());
                    getAllAddress(userDataInfoBean.getData().getUserId(), userDataInfoBean.getData().getUserOrgId());
                } else {
                    ToastTool.showText(getApplicationContext(), "没有找到该卡所对应的用户信息！");
                }
            }
        });
    }

    @Override
    protected void onResume() {
        if (userDataInfoBean != null) {
            getAllAddress(userDataInfoBean.getData().getUserId(), userDataInfoBean.getData().getUserOrgId());
        }
        super.onResume();
    }

    public void payByCard(String userId, String orderid, String payList, double totalFee) {
        LRequest lRequest = new LRequest();
        lRequest.addParam("token", mToken);
        lRequest.addParam("userId", userId);
        lRequest.addParam("orderId", orderid);
        lRequest.addParam("paylist", payList);
        lRequest.addParam("totalFee", totalFee);
        lRequest.setUri(ServerPort.PAY_BY_CARD);
        lRequest.setUriType(UrlsTools.FOOD_INFO);
        lRequest.setIp(UrlsTools.REQ_URL);
        lRequest.setType(String.class);
        requestData(lRequest, new NetDataListener<String>() {
            @Override
            public void onError(Throwable t) {
                T.showAnimErrorToast(getApplicationContext(), "请求超时！");
            }

            @Override
            public void onNext(String responseBean, String code) {
                Log.d(TAG, "responseBean==" + responseBean);
                if (responseBean != null && "0".equals(code)) {
                    showInfo(0);
                } else {
                    showInfo(1);
                }
            }
        });
    }

    private void showInfo(final int payStatus) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        if (payStatus == 0) {
            builder.setTitle("订单支付成功！");
            builder.setMessage("\n" + "订单支付成功，祝您用餐愉快！" + "\n");
        } else {
            builder.setTitle("订单支付失败！");
            builder.setMessage("\n" + "订单支付，请查看订单重新支付！" + "\n");
        }
        builder.setNegativeButton("确认退出", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                clearViewDataInterfaces.clearShopData("1");
                finish();
//                if (payStatus == 0) {
//                    clearViewDataInterfaces.clearShopData("1");
////                    Intent intent = new Intent(getApplicationContext(), LlhFoodOrderFragment.class);
////                    startActivity(intent);
//                } else {
//                    clearViewDataInterfaces.clearShopData("1");
////                    Intent intent = new Intent(getApplicationContext(), LlhFoodOrderFragment.class);
////                    startActivity(intent);
//                }
                dialog.cancel();
            }
        });
        builder.setPositiveButton("继续订购", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                clearViewDataInterfaces.clearShopData("0");
                finish();
                dialog.cancel();
            }
        });
        builder.show();
    }


    static ClearViewDataInterface clearViewDataInterfaces = null;

    public static void registCallBack(ClearViewDataInterface clearViewDataInterface) {
        clearViewDataInterfaces = clearViewDataInterface;
    }


    @Override
    public void showProgress() {
        try {
            showProgress(SubFoodOrderInfoActivity.this);
        } catch (Exception e) {

        }
    }

    @Override
    public void hideProgress() {
        try {
            closeProgress();
        } catch (Exception e) {

        }
    }

    @Override
    protected int getlayout() {
        return R.layout.llh_shoping_food_order;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void doBasess() {

    }

    @Override
    protected INetRequestManager getRequestManager() {
        return NetRequestManager.getInstance();
    }


}
